home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1994
/
MacHack 1994.toast
/
MacHack™94
/
Talks & Papers
/
Michael D. Crawford↵
/
Word Services SDK 1.0.5
/
Writeswell Jr. Source
/
PrintWWJr.c
< prev
next >
Wrap
Text File
|
1993-03-17
|
7KB
|
340 lines
/* PrintWWJr.c
* Handle printing in Writeswell Jr.
*
* ©1992 Working Software, Inc.
* This source code is copyrighted. Permission is granted to use the Word Services
* portion of the Writeswell Jr. source code in your own programs, but you
* may not distribute the Writeswell Jr. word-processor code as a
* commercial product. If you modify the code, please do not call it
* Writeswell Jr. (or Writeswell.) This will ensure that people understand the
* program and don’t have to deal with a number of different versions with
* who-knows-what going on in the code.
*
* Writeswell Jr. and Writeswell are trademarks of Working Software, Inc.
*
* 17 Oct 92 Mike Crawford - The third anniversary of the Loma Prieta Earthquake.
* Downtown Santa Cruz is still under reconstruction.
*/
#include <EPPC.h>
#include <AppleEvents.h>
#include <AEObjects.h>
#include <Printing.h>
#include "AERegistry.h"
#include "WordServices.h"
#include "TestBed.h"
#include "TBConstants.h"
#include "Gripe.h"
#include "Scroll.h"
#include "Prefs.h"
#include "TBGlobals.h"
#include "PrintWWJr.h"
#include "UnloadStuff.h"
#include "PageSetup.h"
void PostPrintingErrors( OSErr theErr );
void PrintPage( Rect rPage, short pageNumber, Boolean *morePages );
void MakePrinterText( THPrint thePrRecHdl );
void SetPrintRect( Rect *rPagePtr );
void SetWindowRect( void );
static Rect gOldDestRect;
static Rect gOldViewRect;
void DoPrint( void )
{
GrafPtr oldPort;
short copies;
short firstPage;
short lastPage;
short numberOfCopies;
short printmgrsResFile;
short realNumberOfPagesInDoc;
short pageNumber;
short printError;
THPrint thePrRecHdl;
TPPrPort thePrPort;
TPrStatus theStatus;
Rect rPage;
Boolean morePages;
GetPort( &oldPort );
thePrRecHdl = GetPrintRecord();
if ( !thePrRecHdl ){
Gripe( "\pCannot get print record" );
return;
}
UnloadForPrint();
PrOpen();
if ( PrError() == noErr ){
printmgrsResFile = CurResFile();
if ( PrJobDialog( thePrRecHdl ) ){
numberOfCopies = (**thePrRecHdl).prJob.iCopies;
firstPage = (**thePrRecHdl).prJob.iFstPage;
lastPage = (**thePrRecHdl).prJob.iLstPage;
/* STUB show printing status dialog */
for ( copies = 1; copies <= numberOfCopies; copies++ ){
/* STUB install idle proc */
/* Restore the resource file to the printer driver */
UseResFile( printmgrsResFile );
thePrPort = PrOpenDoc( thePrRecHdl,
(TPPrPort)NULL,
(Ptr)NULL );
pageNumber = firstPage;
rPage = (**thePrRecHdl).prInfo.rPage;
SetPrintRect( &rPage ); /* Set TE Rec to fit on printer paper */
morePages = true;
while ( pageNumber <= lastPage && morePages && PrError() == noErr ){
PicHandle thePict;
GrafPtr curPort;
GetPort( &curPort );
SetPort( gDocWindow );
thePict = OpenPicture( &rPage );
/*ClipRect( &(thePort->portRect) );*/
/*ClipRect( &rPage );*/
if ( !thePict ){
PrSetError( memFullErr );
}else{
PrintPage( rPage, pageNumber, &morePages );
ClosePicture();
SetPort( curPort );
PrOpenPage( thePrPort, (TPRect)NULL );
if ( PrError() == noErr ){
DrawPicture( thePict, &rPage );
}
PrClosePage( thePrPort );
DisposeHandle( thePict );
}
pageNumber++;
}/* while pageNumber */
SetWindowRect(); /* Restore TE Rec to fit in window */
PrCloseDoc( thePrPort );
if (!PrError() &&
((*thePrRecHdl)->prJob.bJDocLoop == bSpoolLoop)){
PrPicFile( thePrRecHdl,
(TPrPort*)NULL,
(Ptr)NULL,
(Ptr)NULL,
&theStatus);
}
}/* for copies */
}else{
/* The print job is being canceled by the user
* from the job dialog
*/
PrSetError( iPrAbort );
}
}/* If PrError */
printError = PrError();
PrClose();
/* 1.0.2 Check for iPrAbort - user canceled Job dialog or pressed Cmd Dot */
if ( printError != noErr && printError != iPrAbort )
PostPrintingErrors( printError );
ReleaseResource( thePrRecHdl );
/* STUB dispose of progress dialog */
SetPort( oldPort );
return;
}
void PostPrintingErrors( OSErr theErr )
{
/* STUB Explain what the error really was */
Gripe( "\pAn error occurred while printing" );
return;
}
void SetPrintRect( Rect *rPagePtr )
{
TEHandle textH;
/* Resize the TextEdit record's dest and view rects to fit the printer paper */
textH = (TEHandle)GetWRefCon( gDocWindow );
gOldDestRect = (*textH)->destRect;
gOldViewRect = (*textH)->viewRect;
(*textH)->destRect = *rPagePtr;
(*textH)->viewRect = *rPagePtr;
TECalText( textH );
return;
}
void SetWindowRect( void )
{
TEHandle textH;
GrafPtr curPort;
/* Restore the TE rec's original view and dest rects */
GetPort( &curPort );
SetPort( gDocWindow );
textH = (TEHandle)GetWRefCon( gDocWindow );
(*textH)->destRect = gOldDestRect;
(*textH)->viewRect = gOldViewRect;
TECalText( textH );
/* Force a redraw of the text */
InvalRect( &gOldViewRect );
SetPort( curPort );
return;
}
void PrintPage( Rect rPage, short pageNumber, Boolean *morePages )
{
TEHandle textH;
GrafPtr curPort;
Rect clipRect;
short docHeight;
short pageHeight;
Rect viewRect;
Rect destRect;
textH = (TEHandle)GetWRefCon( gDocWindow );
docHeight = TEGetHeight( 1, (*textH)->nLines, textH );
pageHeight = rPage.bottom - rPage.top;
if ( pageHeight * pageNumber > docHeight ){
*morePages = false;
}else{
*morePages = true;
}
SetRect( &clipRect, 0, 0, 0, 0 );
ClipRect( &clipRect );
viewRect = (*textH)->viewRect;
destRect = (*textH)->destRect;
TEScroll( 0, viewRect.top - destRect.top, textH );
TEScroll( 0, - ( pageHeight * (pageNumber - 1) ), textH );
clipRect = rPage;
/*
clipRect.top += (pageHeight * (pageNumber - 1) );
clipRect.bottom += (pageHeight * (pageNumber - 1) );
*/
ClipRect( &clipRect );
TEUpdate( &rPage, textH );
return;
}
#ifdef NEVER
void MakePrinterText( THPrint thePrRecHdl )
{
Rect destRect;
Rect viewRect;
CharsHandle textHdl;
TEStyleHandle stylHdl;
TEHandle winTEHdl;
long textLen;
short oldStart;
short oldEnd;
/* If there are any errors, we post them into the printer manager, so
* that upon return, the error is checked and we will exit the printing loop.
* I think that should work properly.
*
* It will have the advantage that the printing loop will be entirely exited
* before the error is actually displayed.
*/
destRect = (*thePrRecHdl)->prInfo.rPage;
viewRect = destRect;
gPrintTextHdl = TEStylNew( &destRect, &viewRect );
if ( !gPrintTextHdl ){
PrSetError( memFullErr );
return;
}
#ifdef NEVER
/* Copy the text from the window's TE rec to the printer's TE rec */
winTEHdl = (TEHandle)GetWRefCon( gDocWindow );
textHdl = TEGetText( winTEHdl );
textLen = GetHandleSize( textHdl );
HLock( textHdl );
TEInsert( *textHdl, textLen, gPrintTextHdl );
HUnlock( textHdl );
/* Copy the styles from the window's TE rec to the printer's */
oldStart = (*winTEHdl)->selStart;
oldEnd = (*winTEHdl)->selEnd;
(*winTEHdl)->selStart = 0;
(*winTEHdl)->selEnd = 32767;
stylHdl = GetStylHandle( winTEHdl );
(*winTEHdl)->selStart = oldStart;
(*winTEHdl)->selEnd = oldEnd;
SetStylHandle( stylHdl, gPrintTextHdl );
#endif
return;
}
#endif